package com.jcrj.action.document;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Date;
import java.util.List;

import net.sf.json.JSONObject;

import com.jcrj.action.BaseAction;
import com.jcrj.common.Constants;
import com.jcrj.entity.ODepartment;
import com.jcrj.entity.ODispatcherTop;
import com.jcrj.entity.ODocDown;
import com.jcrj.entity.ODocument;
import com.jcrj.entity.OForm;
import com.jcrj.entity.OFormType;
import com.jcrj.entity.OInfoContent;
import com.jcrj.entity.ONode;
import com.jcrj.entity.ONodeTransaction;
import com.jcrj.entity.OProcessinstance;
import com.jcrj.entity.OTaskActor;
import com.jcrj.entity.OTypeSet;
import com.jcrj.entity.OUpdateHis;
import com.jcrj.entity.OUser;
import com.jcrj.entity.OWorkflow;
import com.jcrj.service.DocumentFlowService;
import com.jcrj.service.SysLogService;
import com.jcrj.service.WorkflowManagerService;
import com.jcrj.util.DateUtil;
import com.jcrj.util.GetText;

public class DocumentFlowAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1059199601225769416L;
	private List<OWorkflow> flowList;
	private List<OUpdateHis> hisList;
	private WorkflowManagerService workflowManagerService;
	private OProcessinstance processinstance;
	private ODocument document;
	private ONodeTransaction nodeTransaction;
	private DocumentFlowService documentFlowService;
	private String docId;
	private Integer nodeTransactionId;
	private List<ODocument> docList;
	private List<OWorkflow> workList;
	private List<OTaskActor> actorList;
	private Integer flowId;
	private Integer actorId;
	private String executors;
	private String orgId;
	private String transitionName;
	private String orgNames;
	private long totalCount;
	private long pageCount;
	private String contentId;
	private String[] userId;
	private String[] ids;
	private String propertyIds;
	private String mustPropertyIds;
	private List<ONode> nodeList;
	private Integer nodeId;
	private ONode flowNode;
	private String department;
	private List<ONodeTransaction> nodeTransactionList;
	private String status;
	private String menuName;
	private String nbyj;
	private String ldps;
	private String blqk;
	private String psnr;
	private String dcdb;
	private String doRead;
	private OWorkflow workflow;
	private List<ODocDown> downList;
	private OInfoContent infoContent;
	private OTypeSet typeSet;
	private ODepartment depart;
	private List<OTypeSet> typeSets;
	private List<ODepartment> departments;
	private String name;
	private String message;
	private List<ONode> backNodeList;
	private String supervisionTag;
	private List<ODispatcherTop> topList;
	private ODispatcherTop dispatcherTop;
	private SysLogService sysLogService;

	public String getSupervisionTag() {
		return this.supervisionTag;
	}

	public void setSupervisionTag(String supervisionTag) {
		this.supervisionTag = supervisionTag;
	}

	public String typeSet() {
		this.totalCount = this.workflowManagerService.getTypeCount(this.name);
		this.pageCount = ((this.totalCount - 1L) / 10L + 1L);
		if (super.getCurrentPage() > this.totalCount) {
			super.setCurrentPage(Long.valueOf(this.totalCount).intValue());
		}
		this.typeSets = this.workflowManagerService.getTypes(this.name, super.getCurrentPage());
		return "success";
	}

	public String typeAdd() {
		return "success";
	}

	public String typeAddSave() {
		try {
			this.typeSet.setCreateTime(new Date());
			this.typeSet.setDel("0");
			this.workflowManagerService.saveType(this.typeSet);
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return "success";
	}

	public String typeUpdate() {
		this.typeSet = this.workflowManagerService.updateType(this.typeSet);
		return "success";
	}

	public String typeUpdateSave() {
		try {
			this.workflowManagerService.updateTypeSave(this.typeSet);
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String typeDelete() {
		try {
			this.workflowManagerService.deleteType(this.ids);
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String getReceiveFlow() throws UnsupportedEncodingException {
		this.menuName = "收文管理";
		OUser user = (OUser) getSession().get("userInfo");
		this.flowList = this.workflowManagerService.getReceiveFlowList(user);
		return "success";
	}

	public String getDispatcherFlow() throws UnsupportedEncodingException {
		this.menuName = "发文管理";
		OUser user = (OUser) getSession().get("userInfo");
		this.flowList = this.workflowManagerService.getDispatcherFlowList(user);
		return "success";
	}

	public String createDocument() {
		try {
			OUser user = (OUser) getSession().get("userInfo");
			this.document = new ODocument();
			this.document.setPrintTime(DateUtil.DateToString(new Date()));
			this.document.setFlowId(this.flowId);
			this.document.setDraftOrg(user.getOrgName());
			this.document.setDraftName(user.getName());
			this.document.setDraftUser(user.getId());
			this.document.setSupervision("无人督办");
			this.flowNode = this.workflowManagerService.getStartNode(this.flowId.intValue());
			this.workflow = this.workflowManagerService.getWorkflow(this.flowId.intValue());
			List list1 = this.workflowManagerService.getChosenFormColumnList(this.flowId.intValue());
			this.propertyIds = this.workflowManagerService.getFormProportyPageNames(list1);
			OForm form = this.workflowManagerService.getForm(this.workflow.getFormId().intValue());
			OFormType fType = this.workflowManagerService.getFormType(form.getFormTypeId().intValue());
			if (fType.getId().equals(Integer.valueOf(1))) {
				this.document.setSfstatus("1");
				this.topList = this.documentFlowService.getDispatcherList(user.getOrgId().intValue());
				return "send";
			}
			this.document.setSfstatus("2");
			this.departments = this.workflowManagerService.getDepartments(user.getOrgId().intValue());
			return "receive";
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public String formValidate() {
		try {
			List list1 = this.workflowManagerService.getFormProportyByNode(this.nodeId.intValue());
			this.propertyIds = this.workflowManagerService.getFormProportyPageNames(list1);
			List list2 = this.workflowManagerService.getMustBeFormProportyIdsByNode(this.nodeId.intValue());
			JSONObject json = new JSONObject();
			json.put("mustbe", list2);
			super.getResponse().setCharacterEncoding("utf-8");
			super.getResponse().getWriter().write(json.toString());
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String getNextNodeList() {
		try {
			this.processinstance = this.workflowManagerService.getProcessinstance(this.document.getProcessId().intValue());
			this.nodeList = this.workflowManagerService.getNextNode(this.processinstance.getNodeId().intValue());
			JSONObject json = new JSONObject();
			json.put("node", this.nodeList);
			super.getResponse().setCharacterEncoding("utf-8");
			super.getResponse().getWriter().write(json.toString());
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String blankOut() {
		return null;
	}

	public String saveDraftOut() {
		try {
			OUser user = (OUser) getSession().get("userInfo");
			OWorkflow flow = this.workflowManagerService.getWorkflow(this.document.getFlowId().intValue());
			this.document.setFlowName(flow.getName());
			this.document.setSfstatus("1");
			this.document.setDraftStaus("0");
			this.document.setCreateTime(new Date());
			if ((this.supervisionTag != null) && (!"".equals(this.supervisionTag))) {
				this.document.setSupervision("由" + user.getName() + "督办");
			}
			this.documentFlowService.saveDocument(this.document, user);
			this.sysLogService.saveLog("公文管理", user.getName(), "添加了" + this.document.getTitle() + "的发文");
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String wordChange() {
		System.out.println("aaaa");
		if (this.document != null) {
			try {
				if ((this.document.getTop() != null) && (!"".equals(this.document.getTop()))) {
					this.document.setTop(URLDecoder.decode(URLDecoder.decode(this.document.getTop(), "UTF-8"), "UTF-8").trim());
				}
				if ((this.document.getPostFont1() != null) && (!"".equals(this.document.getPostFont1()))) {
					this.document.setPostFont1(URLDecoder.decode(URLDecoder.decode(this.document.getPostFont1(), "UTF-8"), "UTF-8").trim());
				}
				if ((this.document.getPostFont2() != null) && (!"".equals(this.document.getPostFont2()))) {
					this.document.setPostFont2(URLDecoder.decode(URLDecoder.decode(this.document.getPostFont2(), "UTF-8"), "UTF-8").trim());
				}
				if ((this.document.getThem() != null) && (!"".equals(this.document.getThem()))) {
					this.document.setThem(URLDecoder.decode(URLDecoder.decode(this.document.getThem(), "UTF-8"), "UTF-8").trim());
				}
				if ((this.document.getWriteFrom() != null) && (!"".equals(this.document.getWriteFrom()))) {
					this.document.setWriteFrom(URLDecoder.decode(URLDecoder.decode(this.document.getWriteFrom(), "UTF-8"), "UTF-8").trim());
				}
				if ((this.document.getTitle() != null) && (!"".equals(this.document.getTitle()))) {
					this.document.setTitle(URLDecoder.decode(URLDecoder.decode(this.document.getTitle(), "UTF-8"), "UTF-8").trim().replaceAll("\n", ""));
				}
				if ((this.document.getSendFrom() != null) && (!"".equals(this.document.getSendFrom())))
					this.document.setSendFrom(URLDecoder.decode(URLDecoder.decode(this.document.getSendFrom(), "UTF-8"), "UTF-8").trim());
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return "success";
	}

	public String saveDraftIn() {
		try {
			OUser user = (OUser) getSession().get("userInfo");
			OWorkflow flow = this.workflowManagerService.getWorkflow(this.document.getFlowId().intValue());
			this.document.setFlowName(flow.getName());
			this.document.setSfstatus("2");
			this.document.setDraftStaus("0");
			this.document.setCreateTime(new Date());
			if ((this.supervisionTag != null) && (!"".equals(this.supervisionTag))) {
				this.document.setSupervision("由" + user.getName() + "督办");
			}
			this.documentFlowService.saveDocument(this.document, user);
			this.sysLogService.saveLog("公文管理", user.getName(), "添加了" + this.document.getTitle() + "的收文");
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String getDraftOutList() {
		OUser user = (OUser) getSession().get("userInfo");
		this.totalCount = this.documentFlowService.countDraft(user.getId().intValue(), "1", super.getTitle(), super.getStartDate(), super.getEndDate())
				.longValue();
		this.pageCount = ((this.totalCount - 1L) / 10L + 1L);
		this.docList = this.documentFlowService.getDraftList(user.getId().intValue(), super.getCurrentPage(), "1", super.getTitle(), super.getStartDate(),
				super.getEndDate());
		return "success";
	}

	public String getDraftInList() {
		OUser user = (OUser) getSession().get("userInfo");
		this.totalCount = this.documentFlowService.countDraft(user.getId().intValue(), "2", super.getTitle(), super.getStartDate(), super.getEndDate())
				.longValue();
		this.pageCount = ((this.totalCount - 1L) / 10L + 1L);
		this.docList = this.documentFlowService.getDraftList(user.getId().intValue(), super.getCurrentPage(), "2", super.getTitle(), super.getStartDate(),
				super.getEndDate());
		return "success";
	}

	public String getDraftDetail() {
		OUser user = (OUser) getSession().get("userInfo");
		this.document = this.documentFlowService.getDocumentById(Integer.parseInt(this.docId));
		this.document.setCreateTime(new Date());
		this.flowId = this.document.getFlowId();
		this.flowNode = this.workflowManagerService.getStartNode(this.flowId.intValue());
		List list1 = this.workflowManagerService.getChosenFormColumnList(this.flowId.intValue());
		this.propertyIds = this.workflowManagerService.getFormProportyPageNames(list1);
		if (this.document.getSfstatus().equals("2")) {
			this.departments = this.workflowManagerService.getDepartments(user.getOrgId().intValue());
			return "receive";
		}
		this.topList = this.documentFlowService.getDispatcherList(user.getOrgId().intValue());
		return "send";
	}

	public String deleteDraftList() {
		try {
			this.documentFlowService.deleteDraftList(this.ids);
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
			return null;
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String updateDraft() {
		try {
			OUser user = (OUser) getSession().get("userInfo");
			this.document.setCreateTime(new Date());
			if ((this.supervisionTag != null) && (!"".equals(this.supervisionTag))) {
				this.document.setSupervision("由" + user.getName() + "督办");
			}
			this.documentFlowService.updateDocument(this.document, user);
			this.sysLogService.saveLog("公文管理", user.getName(), "修改了" + this.document.getTitle() + "的公文");
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
			return null;
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String passDraft() {
		try {
			OUser user = (OUser) getSession().get("userInfo");
			OWorkflow w = this.workflowManagerService.getWorkflow(this.document.getFlowId().intValue());
			this.document.setFlowName(w.getName());
			this.document.setCreateTime(new Date());
			this.document.setReject("1");
			this.document.setDraftStaus("1");
			if ((this.propertyIds != null) && (!"".equals(this.propertyIds))) {
				if (this.propertyIds.contains("nbyj")) {
					this.document.setNbyj(GetText.getFwHtmlText(this.document.getNbyj(), user.getName()));
				}
				if (this.propertyIds.contains("ldps")) {
					this.document.setLdps(GetText.getFwHtmlText(this.document.getLdps(), user.getName()));
				}
				if (this.propertyIds.contains("dcdb")) {
					this.document.setDcdb(GetText.getFwHtmlText(this.document.getDcdb(), user.getName()));
				}
				if (this.propertyIds.contains("blqk")) {
					this.document.setBlqk(GetText.getFwHtmlText(this.document.getBlqk(), user.getName()));
				}

				if (this.propertyIds.contains("cbdwyj")) {
					this.document.setOrgSugesstion(GetText.getFwHtmlText(this.document.getOrgSugesstion(), user.getName()));
				}
				if (this.propertyIds.contains("hq")) {
					this.document.setCounterSign(GetText.getFwHtmlText(this.document.getCounterSign(), user.getName()));
				}
				if (this.propertyIds.contains("hg")) {
					this.document.setCheckDraft(GetText.getFwHtmlText(this.document.getCheckDraft(), user.getName()));
				}
				if (this.propertyIds.contains("shyj")) {
					this.document.setShyj(GetText.getFwHtmlText(this.document.getShyj(), user.getName()));
				}
				if (this.propertyIds.contains("syyj")) {
					this.document.setSyyj(GetText.getFwHtmlText(this.document.getSyyj(), user.getName()));
				}
				if (this.propertyIds.contains("qf")) {
					this.document.setSignOff(GetText.getFwHtmlText(this.document.getSignOff(), user.getName()));
				}
			}
			if ((this.supervisionTag != null) && (!"".equals(this.supervisionTag))) {
				this.document.setSupervision("由" + user.getName() + "督办");
			}
			this.documentFlowService.saveDraftDocument(this.document, user, w.getId().intValue(), this.nodeId.intValue(), this.executors, this.message);
			this.sysLogService.saveLog("公文管理", user.getName(), "提交了" + this.document.getTitle() + "的公文文");
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String searchMyDocumentOut() {
		this.menuName = "发文管理";
		OUser user = (OUser) getSession().get("userInfo");
		List agents = this.sysLogService.getFlowAgentUser(user);
		String process = this.workflowManagerService.getProcessinstanceList(user.getId().intValue(), agents);
		this.totalCount = this.documentFlowService.countMyDocument(process, "1", super.getTitle(), super.getStartDate(), super.getEndDate(), super.getFwzh())
				.longValue();
		this.pageCount = ((this.totalCount - 1L) / 10L + 1L);
		this.docList = this.documentFlowService.getDocumentList(process, super.getCurrentPage(), "1", super.getTitle(), super.getStartDate(),
				super.getEndDate(), super.getFwzh());
		return "success";
	}

	public String searchAllDocumentOut() {
		String process = this.workflowManagerService.getAdminProcessList("task");
		this.totalCount = this.documentFlowService.countMyDocument(process, "1", super.getTitle(), super.getStartDate(), super.getEndDate(), super.getFwzh())
				.longValue();
		this.pageCount = ((this.totalCount - 1L) / 10L + 1L);
		this.docList = this.documentFlowService.getDocumentList(process, super.getCurrentPage(), "1", super.getTitle(), super.getStartDate(),
				super.getEndDate(), super.getFwzh());
		return "success";
	}

	public String searchMyDocumentIn() {
		this.menuName = "收文管理";
		OUser user = (OUser) getSession().get("userInfo");
		List agents = this.sysLogService.getFlowAgentUser(user);
		String process = this.workflowManagerService.getProcessinstanceList(user.getId().intValue(), agents);
		this.totalCount = this.documentFlowService.countMyDocument(process, "2", super.getTitle(), super.getStartDate(), super.getEndDate(), super.getFwzh())
				.longValue();
		this.pageCount = ((this.totalCount - 1L) / 10L + 1L);
		this.docList = this.documentFlowService.getDocumentList(process, super.getCurrentPage(), "2", super.getTitle(), super.getStartDate(),
				super.getEndDate(), super.getFwzh());
		return "success";
	}

	public String searchAllDocumentIn() {
		String process = this.workflowManagerService.getAdminProcessList("task");
		this.totalCount = this.documentFlowService.countMyDocument(process, "2", super.getTitle(), super.getStartDate(), super.getEndDate(), super.getFwzh())
				.longValue();
		this.pageCount = ((this.totalCount - 1L) / 10L + 1L);
		this.docList = this.documentFlowService.getDocumentList(process, super.getCurrentPage(), "2", super.getTitle(), super.getStartDate(),
				super.getEndDate(), super.getFwzh());
		return "success";
	}

	public String getTaskDoc() {
		OUser user = (OUser) super.getSession().get("userInfo");
		this.document = this.documentFlowService.getDocumentById(Integer.parseInt(this.docId));
		this.processinstance = this.workflowManagerService.getProcessinstance(this.document.getProcessId().intValue());
		this.nodeList = this.workflowManagerService.getNextNode(this.processinstance.getNodeId().intValue());
		List proportyList = this.workflowManagerService.getWriteFormProportyIdsByNode(this.processinstance.getNodeId().intValue());
		this.propertyIds = this.workflowManagerService.getFormProportyPageNames(proportyList);
		this.flowNode = this.workflowManagerService.getFlowNode(this.processinstance.getNodeId().intValue());
		this.backNodeList = this.workflowManagerService.getBackNodeList(this.processinstance.getId().intValue(), this.processinstance.getNodeId().intValue());
		if (this.document.getSfstatus().equals("2")) {
			this.departments = this.workflowManagerService.getDepartments(user.getOrgId().intValue());
			return "receive";
		}
		this.topList = this.documentFlowService.getDispatcherList(user.getOrgId().intValue());
		return "send";
	}

	public String getDoneTaskDoc() {
		OUser user = (OUser) super.getSession().get("userInfo");
		this.document = this.documentFlowService.getDocumentById(Integer.parseInt(this.docId));
		if (this.document != null) {
			String id = super.getRequest().getParameter("id");
			if ((id != null) && (!"".equals(id))) {
				ODocDown doc = this.documentFlowService.getDocDownById(Integer.parseInt(id));
				doc.setIsRead("1");
				this.documentFlowService.updateDocDown(doc);
			}
			if (this.document.getSfstatus().equals("2")) {
				this.departments = this.workflowManagerService.getDepartments(user.getOrgId().intValue());
				this.downList = this.documentFlowService.findDocDownListByDoc(this.document.getId().intValue());
				return "receive";
			}
			this.topList = this.documentFlowService.getDispatcherList(user.getOrgId().intValue());
			return "send";
		}

		return null;
	}

	public String documentSysUpdate() {
		OUser user = (OUser) super.getSession().get("userInfo");
		this.document = this.documentFlowService.getDocumentById(Integer.parseInt(this.docId));
		this.hisList = this.documentFlowService.getHisList(Integer.parseInt(this.docId));
		if (this.document.getSfstatus().equals("2")) {
			this.departments = this.workflowManagerService.getDepartments(user.getOrgId().intValue());
			return "receive";
		}
		this.topList = this.documentFlowService.getDispatcherList(user.getOrgId().intValue());
		return "send";
	}

	public String updateSysDocument() {
		try {
			OUser user = (OUser) super.getSession().get("userInfo");
			ODocument doc = this.documentFlowService.getDocumentById(this.document.getId().intValue());

			doc.setType(this.document.getType());
			doc.setPostFont1(this.document.getPostFont1());
			doc.setPostFont2(this.document.getPostFont2());
			doc.setPostFont3(this.document.getPostFont3());
			doc.setDraftOrg(this.document.getDraftOrg());
			doc.setArticleNumber(this.document.getArticleNumber());
			doc.setBeizhu(this.document.getBeizhu());
			doc.setTitle(this.document.getTitle());
			doc.setTop(this.document.getTop());
			doc.setMjStatu(this.document.getMjStatu());
			doc.setHjStatu(this.document.getHjStatu());
			doc.setPrint(this.document.getPrint());
			doc.setPrintTime(this.document.getPrintTime());
			doc.setFjbs(this.document.getFjbs());
			doc.setFileArray(this.document.getFileArray());
			doc.setTextId(this.document.getTextId());
			doc.setWriteFrom(this.document.getWriteFrom());
			doc.setSendFrom(this.document.getSendFrom());
			doc.setThem(this.document.getThem());
			doc.setContentId(this.document.getContentId());
			this.documentFlowService.updateDocument(doc);
			if (this.document.getSfstatus().equals("2"))
				this.documentFlowService.saveUpdateHis(user.getName(), doc.getId().intValue(), "修改了收文" + doc.getTitle());
			else {
				this.documentFlowService.saveUpdateHis(user.getName(), doc.getId().intValue(), "修改了发文" + doc.getTitle());
			}
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String passDoc() {
		try {
			OUser user = (OUser) getSession().get("userInfo");
			ODocument doc = this.documentFlowService.getDocumentById(this.document.getId().intValue());
			doc.setType(this.document.getType());
			doc.setPostFont1(this.document.getPostFont1());
			doc.setPostFont2(this.document.getPostFont2());
			doc.setPostFont3(this.document.getPostFont3());
			doc.setDraftOrg(this.document.getDraftOrg());
			doc.setArticleNumber(this.document.getArticleNumber());
			doc.setBeizhu(this.document.getBeizhu());
			doc.setCreateTime(this.document.getCreateTime());
			doc.setTitle(this.document.getTitle());
			doc.setTop(this.document.getTop());
			doc.setMjStatu(this.document.getMjStatu());
			doc.setHjStatu(this.document.getHjStatu());
			doc.setPrint(this.document.getPrint());
			doc.setPrintTime(this.document.getPrintTime());
			doc.setFjbs(this.document.getFjbs());
			doc.setFileArray(this.document.getFileArray());
			doc.setTextId(this.document.getTextId());
			doc.setWriteFrom(this.document.getWriteFrom());
			doc.setSendFrom(this.document.getSendFrom());
			doc.setThem(this.document.getThem());
			doc.setContentId(this.document.getContentId());
			if ((this.propertyIds != null) && (!"".equals(this.propertyIds))) {
				if (this.propertyIds.contains("nbyj")) {
					doc.setNbyj(Constants.isEmpety(doc.getNbyj()) + GetText.getFwHtmlText(this.nbyj, user.getName()));
				}
				if (this.propertyIds.contains("ldps")) {
					doc.setLdps(Constants.isEmpety(doc.getLdps()) + GetText.getFwHtmlText(this.ldps, user.getName()));
				}
				if (this.propertyIds.contains("dcdb")) {
					doc.setDcdb(Constants.isEmpety(doc.getDcdb()) + GetText.getFwHtmlText(this.dcdb, user.getName()));
				}
				if (this.propertyIds.contains("blqk")) {
					doc.setBlqk(Constants.isEmpety(doc.getBlqk()) + GetText.getFwHtmlText(this.blqk, user.getName()));
				}

				if (this.propertyIds.contains("cbdwyj")) {
					doc.setOrgSugesstion(Constants.isTextEmpety(doc.getOrgSugesstion())
							+ GetText.getFwHtmlText(this.document.getOrgSugesstion(), user.getName()));
				}
				if (this.propertyIds.contains("hq")) {
					doc.setCounterSign(Constants.isTextEmpety(doc.getCounterSign()) + GetText.getFwHtmlText(this.document.getCounterSign(), user.getName()));
				}
				if (this.propertyIds.contains("hg")) {
					doc.setCheckDraft(Constants.isTextEmpety(doc.getCheckDraft()) + GetText.getFwHtmlText(this.document.getCheckDraft(), user.getName()));
				}
				if (this.propertyIds.contains("shyj")) {
					doc.setShyj(Constants.isTextEmpety(doc.getShyj()) + GetText.getFwHtmlText(this.document.getShyj(), user.getName()));
				}
				if (this.propertyIds.contains("syyj")) {
					doc.setSyyj(Constants.isTextEmpety(doc.getSyyj()) + GetText.getFwHtmlText(this.document.getSyyj(), user.getName()));
				}
				if (this.propertyIds.contains("qf")) {
					doc.setSignOff(Constants.isTextEmpety(doc.getSignOff()) + GetText.getFwHtmlText(this.document.getSignOff(), user.getName()));
				}
			}
			if ((this.supervisionTag != null) && (!"".equals(this.supervisionTag)))
				doc.setSupervision("由" + user.getName() + "督办");
			else {
				doc.setSupervision("无人督办");
			}
			this.documentFlowService.saveTransitionDocument(doc, doc.getFlowId().intValue(), this.nodeId.intValue(), this.executors, user, this.message);
			this.sysLogService.saveLog("公文管理", user.getName(), "提交了" + this.document.getTitle() + "的公文");
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String rejectDocment() {
		try {
			OUser user = (OUser) super.getSession().get("userInfo");
			ODocument doc = this.documentFlowService.getDocumentById(Integer.parseInt(this.docId));
			this.documentFlowService.updateRejectDocument(doc, this.status, user, this.message);
			this.sysLogService.saveLog("公文管理", user.getName(), "驳回了" + doc.getTitle() + "的公文");
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String getDoneDocOutList() {
		this.menuName = "发文管理";
		OUser user = (OUser) getSession().get("userInfo");
		String process = this.workflowManagerService.getDoneProcessinstanceList(user.getId().intValue());
		this.totalCount = this.documentFlowService.countMyDocument(process, "1", super.getTitle(), super.getStartDate(), super.getEndDate(), super.getFwzh())
				.longValue();
		this.pageCount = ((this.totalCount - 1L) / 10L + 1L);
		this.docList = this.documentFlowService.getDocumentList(process, super.getCurrentPage(), "1", super.getTitle(), super.getStartDate(),
				super.getEndDate(), super.getFwzh());
		return "success";
	}

	public String getDoneAllDocOutList() {
		String process = this.workflowManagerService.getAdminProcessList("end");
		this.totalCount = this.documentFlowService.countMyDocument(process, "1", super.getTitle(), super.getStartDate(), super.getEndDate(), super.getFwzh())
				.longValue();
		this.pageCount = ((this.totalCount - 1L) / 10L + 1L);
		this.docList = this.documentFlowService.getDocumentList(process, super.getCurrentPage(), "1", super.getTitle(), super.getStartDate(),
				super.getEndDate(), super.getFwzh());
		return "success";
	}

	public String getDoneDocInList() {
		this.menuName = "收文管理";
		OUser user = (OUser) getSession().get("userInfo");
		String process = this.workflowManagerService.getDoneProcessinstanceList(user.getId().intValue());
		this.totalCount = this.documentFlowService.countMyDocument(process, "2", super.getTitle(), super.getStartDate(), super.getEndDate(), super.getFwzh())
				.longValue();
		this.pageCount = ((this.totalCount - 1L) / 10L + 1L);
		this.docList = this.documentFlowService.getDocumentList(process, super.getCurrentPage(), "2", super.getTitle(), super.getStartDate(),
				super.getEndDate(), super.getFwzh());
		return "success";
	}

	public String getDoneAllDocInList() {
		String process = this.workflowManagerService.getAdminProcessList("end");
		this.totalCount = this.documentFlowService.countMyDocument(process, "2", super.getTitle(), super.getStartDate(), super.getEndDate(), super.getFwzh())
				.longValue();
		this.pageCount = ((this.totalCount - 1L) / 10L + 1L);
		this.docList = this.documentFlowService.getDocumentList(process, super.getCurrentPage(), "2", super.getTitle(), super.getStartDate(),
				super.getEndDate(), super.getFwzh());
		return "success";
	}

	public String getDocDownList() {
		try {
			String look = super.getRequest().getParameter("look");
			if ((look != null) && (!"".equals(look)))
				this.docId = look;
			OUser user = (OUser) getSession().get("userInfo");
			this.totalCount = this.documentFlowService.getDocDownCount(super.getTitle(), super.getStartDate(), super.getEndDate(), user.getId().toString(),
					super.getCurrentPage());
			this.pageCount = ((this.totalCount - 1L) / 10L + 1L);
			if (super.getCurrentPage() > this.pageCount) {
				super.setCurrentPage(Long.valueOf(this.pageCount).intValue());
			}
			this.downList = this.documentFlowService.findDocDownList(super.getTitle(), super.getStartDate(), super.getEndDate(), user.getId().toString(),
					super.getCurrentPage(), (look == null) || ("".equals(look)) ? "0" : look);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "success";
	}

	public String deleteDocDown() {
		try {
			this.documentFlowService.deleteDocDown(this.ids);
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String saveDocDown() {
		try {
			this.documentFlowService.saveDocDown(this.userId, Integer.parseInt(this.docId), this.status);
			getResponse().getWriter().write("success");
			getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public String viewWordFile() {
		ODocDown doc = this.documentFlowService.getDocDownById(Integer.parseInt(this.docId));
		ODocument document = this.documentFlowService.getDocumentById(doc.getDocId().intValue());
		if (document != null) {
			if (!"1".equals(doc.getIsRead())) {
				doc.setIsRead("1");
				this.documentFlowService.updateDocDown(doc);
			}
			setContentId(document.getContentId());
		}
		return "success";
	}

	public String dispatcherTopList() {
		this.totalCount = this.documentFlowService.contDispatcherTop(this.name).longValue();
		this.pageCount = ((this.totalCount - 1L) / 10L + 1L);
		if (super.getCurrentPage() > this.pageCount) {
			super.setCurrentPage(Long.valueOf(this.pageCount).intValue());
		}
		this.topList = this.documentFlowService.dispatcherTopList(this.name, super.getCurrentPage());
		return "success";
	}

	public String topInit() {
		return "success";
	}

	public String saveDispatcherTop() {
		try {
			OUser user = (OUser) super.getSession().get("userInfo");
			this.dispatcherTop.setOrgIds(this.orgId);
			this.dispatcherTop.setOrgName(this.orgNames);
			this.dispatcherTop.setUserId(user.getId());
			this.dispatcherTop.setUserName(user.getName());
			this.documentFlowService.saveDispatcherTop(this.dispatcherTop, this.orgId, this.orgNames);
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String getDispatcherTopInfo() {
		this.dispatcherTop = this.documentFlowService.getDispatcherTop(this.flowId.intValue());
		return "success";
	}

	public String updateDispatcherTop() {
		try {
			OUser user = (OUser) super.getSession().get("userInfo");
			this.dispatcherTop.setOrgIds(this.orgId);
			this.dispatcherTop.setOrgName(this.orgNames);
			this.dispatcherTop.setUserId(user.getId());
			this.dispatcherTop.setUserName(user.getName());
			this.documentFlowService.updateDispatcherTop(this.dispatcherTop, this.orgId, this.orgNames);
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String deleteDispatcherTop() {
		try {
			this.documentFlowService.deleteDispatcherTop(this.ids);
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String getDispatcherTopShort() {
		try {
			super.getResponse().setCharacterEncoding("UTF-8");
			String shortName = this.documentFlowService.getDispatcherTopShort(this.name);
			String maxTop = this.documentFlowService.getMaxTop(this.name, this.department, this.status);
			JSONObject json = new JSONObject();
			json.put("shortName", shortName);
			json.put("maxTop", maxTop);
			super.getResponse().getWriter().write(json.toString());
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String getReceiveType() {
		try {
			super.getResponse().setCharacterEncoding("UTF-8");
			String maxTop = this.documentFlowService.getMaxTop(this.name, this.department, this.status);
			JSONObject json = new JSONObject();
			json.put("maxTop", maxTop);
			super.getResponse().getWriter().write(json.toString());
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public String deleteOverFlow() {
		try {
			this.documentFlowService.deleteOverFlow(this.ids);
			super.getResponse().getWriter().write("success");
			super.getResponse().getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				super.getResponse().getWriter().close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public List<ODocDown> getDownList() {
		return this.downList;
	}

	public void setDownList(List<ODocDown> downList) {
		this.downList = downList;
	}

	public ODocument getDocument() {
		return this.document;
	}

	public void setDocument(ODocument document) {
		this.document = document;
	}

	public String getDocId() {
		return this.docId;
	}

	public void setDocId(String docId) {
		this.docId = docId;
	}

	public List<ODocument> getDocList() {
		return this.docList;
	}

	public void setDocList(List<ODocument> docList) {
		this.docList = docList;
	}

	public List<OWorkflow> getWorkList() {
		return this.workList;
	}

	public void setWorkList(List<OWorkflow> workList) {
		this.workList = workList;
	}

	public Integer getFlowId() {
		return this.flowId;
	}

	public void setFlowId(Integer flowId) {
		this.flowId = flowId;
	}

	public Integer getActorId() {
		return this.actorId;
	}

	public void setActorId(Integer actorId) {
		this.actorId = actorId;
	}

	public String getTransitionName() {
		return this.transitionName;
	}

	public void setTransitionName(String transitionName) {
		this.transitionName = transitionName;
	}

	public String getOrgNames() {
		return this.orgNames;
	}

	public void setOrgNames(String orgNames) {
		this.orgNames = orgNames;
	}

	public long getTotalCount() {
		return this.totalCount;
	}

	public void setTotalCount(long totalCount) {
		this.totalCount = totalCount;
	}

	public long getPageCount() {
		return this.pageCount;
	}

	public void setPageCount(long pageCount) {
		this.pageCount = pageCount;
	}

	public String[] getUserId() {
		return this.userId;
	}

	public void setUserId(String[] userId) {
		this.userId = userId;
	}

	public List<OWorkflow> getFlowList() {
		return this.flowList;
	}

	public void setFlowList(List<OWorkflow> flowList) {
		this.flowList = flowList;
	}

	public WorkflowManagerService getWorkflowManagerService() {
		return this.workflowManagerService;
	}

	public void setWorkflowManagerService(WorkflowManagerService workflowManagerService) {
		this.workflowManagerService = workflowManagerService;
	}

	public OProcessinstance getProcessinstance() {
		return this.processinstance;
	}

	public void setProcessinstance(OProcessinstance processinstance) {
		this.processinstance = processinstance;
	}

	public ONodeTransaction getNodeTransaction() {
		return this.nodeTransaction;
	}

	public void setNodeTransaction(ONodeTransaction nodeTransaction) {
		this.nodeTransaction = nodeTransaction;
	}

	public DocumentFlowService getDocumentFlowService() {
		return this.documentFlowService;
	}

	public void setDocumentFlowService(DocumentFlowService documentFlowService) {
		this.documentFlowService = documentFlowService;
	}

	public Integer getNodeTransactionId() {
		return this.nodeTransactionId;
	}

	public void setNodeTransactionId(Integer nodeTransactionId) {
		this.nodeTransactionId = nodeTransactionId;
	}

	public List<ONodeTransaction> getNodeTransactionList() {
		return this.nodeTransactionList;
	}

	public void setNodeTransactionList(List<ONodeTransaction> nodeTransactionList) {
		this.nodeTransactionList = nodeTransactionList;
	}

	public List<ONode> getNodeList() {
		return this.nodeList;
	}

	public void setNodeList(List<ONode> nodeList) {
		this.nodeList = nodeList;
	}

	public Integer getNodeId() {
		return this.nodeId;
	}

	public void setNodeId(Integer nodeId) {
		this.nodeId = nodeId;
	}

	public List<OTaskActor> getActorList() {
		return this.actorList;
	}

	public void setActorList(List<OTaskActor> actorList) {
		this.actorList = actorList;
	}

	public String getExecutors() {
		return this.executors;
	}

	public void setExecutors(String executors) {
		this.executors = executors;
	}

	public String getOrgId() {
		return this.orgId;
	}

	public void setOrgId(String orgId) {
		this.orgId = orgId;
	}

	public String getDepartment() {
		return this.department;
	}

	public void setDepartment(String department) {
		this.department = department;
	}

	public ONode getFlowNode() {
		return this.flowNode;
	}

	public void setFlowNode(ONode flowNode) {
		this.flowNode = flowNode;
	}

	public String getPropertyIds() {
		return this.propertyIds;
	}

	public void setPropertyIds(String propertyIds) {
		this.propertyIds = propertyIds;
	}

	public String getMustPropertyIds() {
		return this.mustPropertyIds;
	}

	public void setMustPropertyIds(String mustPropertyIds) {
		this.mustPropertyIds = mustPropertyIds;
	}

	public String getStatus() {
		return this.status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public OInfoContent getInfoContent() {
		return this.infoContent;
	}

	public void setInfoContent(OInfoContent infoContent) {
		this.infoContent = infoContent;
	}

	public String[] getIds() {
		return this.ids;
	}

	public void setIds(String[] ids) {
		this.ids = ids;
	}

	public String getContentId() {
		return this.contentId;
	}

	public void setContentId(String contentId) {
		this.contentId = contentId;
	}

	public String getMenuName() {
		return this.menuName;
	}

	public void setMenuName(String menuName) {
		this.menuName = menuName;
	}

	public String getNbyj() {
		return this.nbyj;
	}

	public void setNbyj(String nbyj) {
		this.nbyj = nbyj;
	}

	public String getLdps() {
		return this.ldps;
	}

	public void setLdps(String ldps) {
		this.ldps = ldps;
	}

	public String getBlqk() {
		return this.blqk;
	}

	public void setBlqk(String blqk) {
		this.blqk = blqk;
	}

	public OWorkflow getWorkflow() {
		return this.workflow;
	}

	public void setWorkflow(OWorkflow workflow) {
		this.workflow = workflow;
	}

	public OTypeSet getTypeSet() {
		return this.typeSet;
	}

	public void setTypeSet(OTypeSet typeSet) {
		this.typeSet = typeSet;
	}

	public ODepartment getDepart() {
		return this.depart;
	}

	public void setDepart(ODepartment depart) {
		this.depart = depart;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<OTypeSet> getTypeSets() {
		return this.typeSets;
	}

	public List<ONode> getBackNodeList() {
		return this.backNodeList;
	}

	public void setBackNodeList(List<ONode> backNodeList) {
		this.backNodeList = backNodeList;
	}

	public void setTypeSets(List<OTypeSet> typeSets) {
		this.typeSets = typeSets;
	}

	public List<ODepartment> getDepartments() {
		return this.departments;
	}

	public void setDepartments(List<ODepartment> departments) {
		this.departments = departments;
	}

	public List<ODispatcherTop> getTopList() {
		return this.topList;
	}

	public void setTopList(List<ODispatcherTop> topList) {
		this.topList = topList;
	}

	public ODispatcherTop getDispatcherTop() {
		return this.dispatcherTop;
	}

	public void setDispatcherTop(ODispatcherTop dispatcherTop) {
		this.dispatcherTop = dispatcherTop;
	}

	public SysLogService getSysLogService() {
		return this.sysLogService;
	}

	public void setSysLogService(SysLogService sysLogService) {
		this.sysLogService = sysLogService;
	}

	public String getPsnr() {
		return this.psnr;
	}

	public void setPsnr(String psnr) {
		this.psnr = psnr;
	}

	public String getDcdb() {
		return this.dcdb;
	}

	public void setDcdb(String dcdb) {
		this.dcdb = dcdb;
	}

	public String getDoRead() {
		return this.doRead;
	}

	public void setDoRead(String doRead) {
		this.doRead = doRead;
	}

	public String getMessage() {
		return this.message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public List<OUpdateHis> getHisList() {
		return this.hisList;
	}

	public void setHisList(List<OUpdateHis> hisList) {
		this.hisList = hisList;
	}
}
